package com.ruoyi.ucar.controller;

import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.ucar.boreq.WithdrawRecordDetailQueryBoReq;
import com.ruoyi.ucar.boreq.WithdrawRecordListQueryBoReq;
import com.ruoyi.ucar.boresp.WithdrawRecordDetailQueryBoResp;
import com.ruoyi.ucar.boresp.WithdrawRecordListQueryBoResp;
import com.ruoyi.ucar.common.CommonVoResp;
import com.ruoyi.ucar.service.ITWithdrawRecordService;
import com.ruoyi.ucar.domain.TWithdrawRecord;
import com.ruoyi.ucar.util.CommonUtil;
import com.ruoyi.ucar.voreq.WithdrawRecordDetailQueryVoReq;
import com.ruoyi.ucar.voreq.WithdrawRecordListQueryVoReq;
import com.ruoyi.ucar.voresp.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 提现记录Controller
 * 
 * @author sungangbin
 * @date 2025-05-13
 */
@Api(value = "提现记录管理",tags = "提现记录管理模块接口")
@RestController
@RequestMapping("/ucar/RawRecord")
public class TWithdrawRecordController extends BaseController
{
    @Autowired
    private ITWithdrawRecordService tWithdrawRecordService;

    /**
     * 查询提现记录列表
     */
    @ApiOperation("提现记录列表")
    @PreAuthorize("@ss.hasPermi('ucar:rawRecord:list')")
    @PostMapping("/list")
    public CommonVoResp<WithdrawRecordListQueryVoResp> list(@RequestBody WithdrawRecordListQueryVoReq withdrawRecordListQueryVoReq)
    {
        logger.info("  提现记录列表查询VO端入口参数:{}",withdrawRecordListQueryVoReq);
        CommonVoResp<WithdrawRecordListQueryVoResp> commonVoResp=new CommonVoResp<>();
        if(
                withdrawRecordListQueryVoReq.getPageIndex()==null||
                        withdrawRecordListQueryVoReq.getPageSize()==null){
            return CommonUtil.setCommonVoRespNoParam(commonVoResp);
        }
        WithdrawRecordListQueryBoReq withdrawRecordListQueryBoReq=CommonUtil.objToObj(withdrawRecordListQueryVoReq, WithdrawRecordListQueryBoReq.class);
        withdrawRecordListQueryBoReq.setPageIndex(withdrawRecordListQueryVoReq.getPageIndex());
        withdrawRecordListQueryBoReq.setPageSize(withdrawRecordListQueryVoReq.getPageSize());
        WithdrawRecordListQueryBoResp withdrawRecordListQueryBoResp=tWithdrawRecordService.queryWithdrawRecordList(withdrawRecordListQueryBoReq);
        if(StringUtils.isNotNull(withdrawRecordListQueryBoResp)){
            WithdrawRecordListQueryVoResp withdrawRecordListQueryVoResp=new WithdrawRecordListQueryVoResp();
            List<WithdrawRecordListQueryVo> withdrawRecordListQueryVos=new ArrayList<>();
            withdrawRecordListQueryVoResp.setTotalCount(withdrawRecordListQueryBoResp.getTotalCount());
            withdrawRecordListQueryVoResp.setTotalPage(withdrawRecordListQueryBoResp.getTotalPage());
            withdrawRecordListQueryBoResp.getWithdrawRecordListQueryBos().forEach(withdrawRecordListQueryBo -> {
                WithdrawRecordListQueryVo withdrawRecordListQueryVo=CommonUtil.objToObj(withdrawRecordListQueryBo, WithdrawRecordListQueryVo.class);
                withdrawRecordListQueryVos.add(withdrawRecordListQueryVo);
            });
            withdrawRecordListQueryVoResp.setWithdrawRecordListQueryVos(withdrawRecordListQueryVos);
            commonVoResp.setData(withdrawRecordListQueryVoResp);
        }else{
            return CommonUtil.setCommonVoRespNoDataError(commonVoResp);
        }
        logger.info("提现记录列表查询出参：{}",commonVoResp);
        return commonVoResp;
    }

    /**
     * 导出提现记录列表
     */
    @PreAuthorize("@ss.hasPermi('ucar:rawRecord:export')")
    @Log(title = "提现记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TWithdrawRecord tWithdrawRecord)
    {
        List<TWithdrawRecord> list = tWithdrawRecordService.selectTWithdrawRecordList(tWithdrawRecord);
        ExcelUtil<TWithdrawRecord> util = new ExcelUtil<TWithdrawRecord>(TWithdrawRecord.class);
        util.exportExcel(response, list, "提现记录数据");
    }

    /**
     * 获取提现记录详细信息
     */
    @ApiOperation("获取提现记录详细信息-id和withdrawRecordUuid，两者传一即可\"")
    @PreAuthorize("@ss.hasPermi('ucar:rawRecord:query')")
    @PostMapping(value = "/detail")
    public CommonVoResp<WithdrawRecordDetailQueryVoResp> withdrawRecordDetail(@RequestBody WithdrawRecordDetailQueryVoReq withdrawRecordDetailQueryVoReq )
    {
        CommonVoResp<WithdrawRecordDetailQueryVoResp> commonVoResp=new CommonVoResp<>();
        logger.info("获取提现记录详细信息入参：{}",withdrawRecordDetailQueryVoReq);
        if(
                withdrawRecordDetailQueryVoReq.getWithdrawRecordUuid()==null&&
                        withdrawRecordDetailQueryVoReq.getId()==null){
            return CommonUtil.setCommonVoRespNoParam(commonVoResp);
        }
        WithdrawRecordDetailQueryBoResp withdrawRecordDetailQueryBoResp=tWithdrawRecordService.withdrawRecordDetail(CommonUtil.objToObj(withdrawRecordDetailQueryVoReq, WithdrawRecordDetailQueryBoReq.class));

        if(StringUtils.isNull(withdrawRecordDetailQueryBoResp)){
            return CommonUtil.setCommonVoRespNoDataError(commonVoResp);
        }else{
            WithdrawRecordDetailQueryVoResp withdrawRecordDetailQueryVoResp=CommonUtil.objToObj(withdrawRecordDetailQueryBoResp,WithdrawRecordDetailQueryVoResp.class);
            commonVoResp.setData(withdrawRecordDetailQueryVoResp);
        }
        logger.info("获取提现记录详细信息出参：{}",commonVoResp);
        return commonVoResp;
    }

    /**
     * 新增提现记录
     */
    @PreAuthorize("@ss.hasPermi('ucar:rawRecord:add')")
    @Log(title = "提现记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TWithdrawRecord tWithdrawRecord)
    {
        return toAjax(tWithdrawRecordService.insertTWithdrawRecord(tWithdrawRecord));
    }

    /**
     * 修改提现记录
     */
    @PreAuthorize("@ss.hasPermi('ucar:rawRecord:edit')")
    @Log(title = "提现记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TWithdrawRecord tWithdrawRecord)
    {
        return toAjax(tWithdrawRecordService.updateTWithdrawRecord(tWithdrawRecord));
    }

    /**
     * 删除提现记录
     */
    @PreAuthorize("@ss.hasPermi('ucar:rawRecord:remove')")
    @Log(title = "提现记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tWithdrawRecordService.deleteTWithdrawRecordByIds(ids));
    }
}
